
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layuiadmin/layui-v2.5.5/layui/css/layui.css" media="all" type="text/css">
</head>
<script type="text/javascript" src="../../layuiadmin/lib/jquery.min.js"></script>
<script>
    var data=parent.PartitionId;
    $(function(){
        $("#workhistoryStartdate").val(data[0].workhistoryStartdate);
        $("#workhistoryEnddate").val(data[0].workhistoryEnddate);
        $("#workhistoryWorkunit").val(data[0].workhistoryWorkunit);
        $("#workhistoryJobPosition").val(data[0].workhistoryJobPosition);
        $("#workhistorySite").val(data[0].workhistorySite);
        $("#empId").val(data[0].empId);
        $("#hrWorkhistoryId").val(data[0].hrWorkhistoryId);
    })  ;
</script>
<body>
<form class="layui-form" action="" lay-filter="example" id="form1">
      <div class="layui-form-item">
         <input name="hrWorkhistoryId" id="hrWorkhistoryId" type="hidden">
            <label class="layui-form-label">开始日期</label>
            <div class="layui-input-inline">
                <input name="workhistoryStartdate" id="workhistoryStartdate" class="layui-input"  type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">结束日期</label>
            <div class="layui-input-inline">
                <input name="workhistoryEnddate" id="workhistoryEnddate" class="layui-input"  type="text" placeholder="yyyy-MM-dd" autocomplete="off" lay-verify="date">
            </div>
        </div>
            <div class="layui-form-item">
                <label class="layui-form-label">工作单位</label>
                <div class="layui-input-block">
                    <input name="workhistoryWorkunit" id="workhistoryWorkunit" class="layui-input" type="text" placeholder="请输入" autocomplete="off" lay-verify="title">
                </div>
            </div>
               <div class="layui-form-item">
                        <label class="layui-form-label">工作职务</label>
                        <div class="layui-input-block">
                            <input name="workhistoryJobPosition" id="workhistoryJobPosition" class="layui-input" type="text" placeholder="请输入" autocomplete="off" lay-verify="title">
                        </div>
                    </div>
        <div class="layui-form-item">
            <label class="layui-form-label">工作类别</label>
            <div class="layui-input-block">
                <select name="workhistoryWorktype" lay-filter="aihao" id="workhistoryWorktype" lay-verify="title1">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
            <div class="layui-form-item">
                <label class="layui-form-label">单位性质</label>
                <div class="layui-input-block">
                    <select name="workhistoryWorknature" id="workhistoryWorknature" lay-filter="aihao"  lay-verify="title1">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
                  <div class="layui-form-item">
                                <label class="layui-form-label">所在地</label>
                                <div class="layui-input-block">
                                    <input name="workhistorySite" id="workhistorySite" class="layui-input" type="text" placeholder="请输入" autocomplete="off" lay-verify="title">
                                </div>
                            </div>
            <input type="hidden" name="empId" id="empId">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" type="submit" lay-filter="demo1" lay-submit="">立即提交</button>
                    </div>
                </div>
</form>
<script src="../../layuiadmin/layui-v2.5.5/layui/layui.js" type="text/javascript"></script>
<script type="text/javascript" src="../../layuiadmin/lib/jquery.min.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate','upload'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        //日期
        laydate.render({
            elem: '#workhistoryStartdate'
        });
        laydate.render({
            elem: '#workhistoryEnddate'
        });
                    laydate.render({	elem: '#qBeginTime',	format: 'yyyy-MM-dd',	done: function (value, date, endDate) {		var startDate = new Date(value).getTime();		var endTime = new Date($('#qEndTime').val()).getTime();		if (endTime < startDate) {			layer.msg('结束时间不能小于开始时间');			$('#qBeginTime').val($('#qEndTime').val());		}	}	})
                       laydate.render({elem: '#qEndTime',	format: 'yyyy-MM-dd',	done: function (value, date, endDate) {		var startDate = new Date($('#qBeginTime').val()).getTime();		var endTime = new Date(value).getTime();		if (endTime < startDate) {			layer.msg('结束时间不能小于开始时间');			$('#qEndTime').val($('#qBeginTime').val());		}	}})
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            title: function(value){
                if(value.length < 1){
                    return '请输入';
                }
            }
            ,title1: function(value){
                if(value.length < 1){
                    return '请选择';
                }
            }
            ,pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });
        //工作类别
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/workleibie.json",
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#workhistoryWorktype').append("<option value="+item.id+">"+item.id+"</option>");
                    })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        })
        var hrWorkhistoryId=data[0].hrWorkhistoryId;
              $.post("http://localhost:8080/HrEmp/workid",{"id":hrWorkhistoryId},function(msg){
                    $("#workhistoryWorktype option").each(function(){
                        if(msg.workhistoryWorktype==$(this).val()){
                            $(this).attr("selected","selected")
                        }
                    });
                    layui.form.render("select");
                });
        //单位性质
        $(function(){
            $.ajax({
                type:"POST",
                url:"../../views/hr/json/workxingzhi.json",
                data:{name:name},
                datatype:"json",
                success:function(data){
                    $.each(data,function (index,item) {
                        $('#workhistoryWorknature').append("<option value="+item.id+">"+item.id+"</option>");
                       })
                    layui.form.render("select");
                },error:function(){
                    alert("失败")
                }
            })
        })
               var hrWorkhistoryId=data[0].hrWorkhistoryId;
                      $.post("http://localhost:8080/HrEmp/workid",{"id":hrWorkhistoryId},function(msg){
                            $("#workhistoryWorknature option").each(function(){
                                if(msg.workhistoryWorknature==$(this).val()){
                                    $(this).attr("selected","selected")
                                }
                            });
                            layui.form.render("select");
                        });
           //监听提交
           form.on('submit(demo1)', function(data){
               var data1=$("#form1").serialize();
               $.ajax({
                   type:"POST",
                   url:"http://localhost:8080/HrEmp/workupdate",
                   data:data1,
                   success:function(data){
                       layer.alert('修改成功',function(){
                           parent.layer.closeAll();
                       })
                       parent.layui.table.reload('listData1')
                   },error:function(){
                       alert("失败")
                   }
               });
               return false;
           });
        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function(){
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>

</body>
</html>